home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6259 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.4 KB

  1. Path: news.tau.ac.il!usenet
  2. From: "Avi L." <avil@sapiens.com>
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: 680X0 -> PPC translator?
  5. Date: Tue, 26 Mar 1996 16:36:07 +0200
  6. Organization: Sapiens Tech.
  7. Message-ID: <315800D7.1854@sapiens.com>
  8. References: <3143E4EB.7303@sapiens.com> <volker.0fsu@vb.franken.de> <31499F8E.26A9@netvision.net.il> <volker.0fw1@vb.franken.de>
  9. NNTP-Posting-Host: honda.sapiens.co.il
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (WinNT; I)
  14.  
  15. Volker Barthelmann wrote:
  16. > Jack (avilev@netvision.net.il) wrote:
  17. > :
  18. > : oh is that so?! unless you get the address from an outside source, such as allocating it YOU
  19. > : must produce it, right?! so you have to have it stored somewhere in the program. if you get it
  20. > No. I can get it from system functions or calculate it. And both possibilities
  21. > can depend on information that is only available at runtime.
  22.  
  23. you're a little confused here, you're talking about run-time values while that isn't necessary 
  24. to know when and how a certain memory space is used. you use the pointers as parameters
  25. replacing the actual run-time addresses. these pointers already exist within the program
  26. and can therefore be analyzed for any changes made to them and how they're being used.
  27. if you perform careful analysis of the pointers, and that means following the changes made
  28. to them by the program, you CAN know in which context they are being used and act 
  29. appropriatly. for example:
  30.  
  31. call _malloc ; let's say register a1 holds the returned address.
  32. move a1,xyz(a7) ; store it in some variable, noting the current value of a7.
  33.  
  34. what i mean is, you use your own value of a7 with an initial value of 0 and follow the
  35. changes made to it resetting it to 0 on assignments. that way you don't need the actual value
  36. of a7 for knowning to which variable it refers to. now you know the address of the pointer to
  37. the allocated block i just malloc()'ed so you can know how it's being used later, eg. code or data.
  38. and bear in mind that all memory allocation routines call evantually AllocMem() function so you 
  39. have the instruction address of where exactly the memory region was allocated and so you can change
  40. the size argument for the function if that memory area is later used for self-modifying code.
  41. also you have to follow any loops which do writes to the area cuz these might be the sections
  42. that copy code into that area and so you have to make the adjustments so that they loop 
  43. according to the translated code size.
  44. granted, if you call some other function in a library which allocates memory and 
  45. assigns it to a pointer argument given to it, then it'll fail but then even the dynamic approach
  46. would fail here since the actual allocation was made in a different module all together and
  47. cannot therefore be changed. this is one of the exceptions to its capabilities i know, but hey
  48. it's not perfect yet.
  49.  
  50. > : from some outside source, such as malloc(), then you don't have it obviously but that being said
  51. > : doesn't imply it's impossible to figure out in which context the address is being used (ie code
  52. > Easy??
  53.  
  54. yes easy, cuz as i said you know where it was allocated and you can change the appropriate 
  55. argument. 
  56.  
  57.  
  58. > : calculated code size, remember that the code is sitting somewhere inside your executable and
  59. > : therefore its size is known, comparing this value to the values pushed to the stack before the
  60. > : malloc() call and you would find the exact word address to change.
  61. > You can't simply change all memory allocations of a certain size, because
  62. > the program could use other chunks of memory that happen to have the same
  63. > size.
  64.  
  65. UUUHHH that's where you're wrong cuz i didn't say change all allocation but only those which are
  66. later used for code (ie self-modifying code, remember) 
  67.  
  68. > And in many programs You won't find any call to e.g. AllocMem with this
  69. > size at all, because the program uses its own memory-pool-routines.
  70. > Etc. etc...
  71.  
  72. but then again it must have allocated the master pool from which it sub-allocates memory from
  73. and besides it must pass that allocator the required size, so you can change it if that segment 
  74. is later used for code, you know the size of the copied code after all and if the size passed to 
  75. the function is sufficient for the translated code then you don't have to do anything otherwise
  76. change it. 
  77. > : > Easy said, but really doing this is a different story. First, You'll have to
  78. > : > kind of disassemble the program and therefore You have to know what is data
  79. > : > and what is code, but that's what You want to decide, so...
  80. > : >
  81. > : > Also doing this kind of analysis is pretty much impossible on Assembler code.
  82. > : your mind is too cluttered with the complexity of things, but saying it isn't possible is simply
  83. > : an unfounded claim.
  84. > It's not unfounded, but I've thought about some things.
  85. > There are much simpler similar problems that are AFAIK proven to be
  86. > undecidable.
  87.  
  88. care to elaborate on this please.
  89.  
  90. > You can't simply 'keep track' of it, because there are loops and recursions
  91. > in a program and if it does some more complicated things it's not possible
  92. > to determine where e.g. a7 points to at a certain instruction, because this
  93. > depends on the current iteration/recursion or other factors that can't be
  94. > known before runtime.
  95.  
  96. what the hell does recursion have to do with anything, it simply calls the function from within 
  97. itself, so what??? if you follow the changes to a7, then you'll always point to the right address,
  98. remember that auto-variables don't exist cuz the programs is not running and so all references are
  99. are register (a7) indirect and so nothing really matters, you use registers not absolute addresses.
  100.  
  101. > What do You mean by ansi-compliant programs and what does this have to do
  102. > with it? 
  103. heheheh, i mean programs that use ansi C conventions for calling functions, register usage etc...
  104.  
  105. > Functions are components of certain high level languages. In machine language
  106. > there are only addresses. Even if this code was generated by a compiler You
  107. > have to keep track of any jump addresses to be able to determine the
  108. > beginning and end of a function and what is code an what is data.
  109.  
  110. gimme one example where i would fail to translate that. believe me it should fine.
  111.  
  112. > Volker
  113. > P.S.: Please don't use more than about 78 characters/line
  114.  
  115. sorry, i didn't really keep track of how long the lines are, maximize your window.
  116.  
  117. Avi Lev.
  118.